import { OrderProductFees } from './orderProductFee';
let _OrderProductFees = OrderProductFees;
/**
 * 拷贝下面两行到 mock/index.js中,即可支持客户端虚拟数据、免服务端连接
 * import OrderProductFeeMock from './mk/mng/computed/day/orderProductFeeMock';
 * OrderProductFeeMock.bootstrap(mock);
 */
export default {
  /**
   * mock bootstrap
   */
  bootstrap(mock) {    
  
    //获取列表 模糊查询、根据关键字查询
    mock.onGet('/mk/mng/computed/day/orderProductFee/listKey').reply(config => {
      let params = config.params;
      let mockOrderProductFees = _OrderProductFees.filter(orderProductFee => {
      	if(params.goodsId||params.goodsId==''){ if( orderProductFee.goodsId.indexOf(params.goodsId)>=0) return true;}
      	if(params.nums||params.nums==''){ if( orderProductFee.nums.indexOf(params.nums)>=0) return true;}
      	if(params.totalPrice||params.totalPrice==''){ if( orderProductFee.totalPrice.indexOf(params.totalPrice)>=0) return true;}
      	if(params.totalFee||params.totalFee==''){ if( orderProductFee.totalFee.indexOf(params.totalFee)>=0) return true;}
      	if(params.orderCount||params.orderCount==''){ if( orderProductFee.orderCount.indexOf(params.orderCount)>=0) return true;}
      	if(params.id||params.id==''){ if( orderProductFee.id.indexOf(params.id)>=0) return true;}
      	if(params.bizDate||params.bizDate==''){ if( orderProductFee.bizDate.indexOf(params.bizDate)>=0) return true;}
      	if(params.startComputedDate||params.startComputedDate==''){ if( orderProductFee.startComputedDate.indexOf(params.startComputedDate)>=0) return true;}
      	if(params.computedStatus||params.computedStatus==''){ if( orderProductFee.computedStatus.indexOf(params.computedStatus)>=0) return true;}
      	if(params.goodsName||params.goodsName==''){ if( orderProductFee.goodsName.indexOf(params.goodsName)>=0) return true;}
      	if(params.shopCount||params.shopCount==''){ if( orderProductFee.shopCount.indexOf(params.shopCount)>=0) return true;}
        return false;
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            data: mockOrderProductFees
          }]);
        }, 1000);
      });
    });
    
    

    //获取列表（分页/不分页）
    mock.onGet('/mk/mng/computed/day/orderProductFee/list').reply(config => {
      let params = config.params;
      let mockOrderProductFees = _OrderProductFees.filter(orderProductFee => {
      	var isTrue=false;
      	if(params.goodsId||params.goodsId==''){if(orderProductFee.goodsId.indexOf(params.goodsId)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.nums||params.nums==''){if(orderProductFee.nums.indexOf(params.nums)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.totalPrice||params.totalPrice==''){if(orderProductFee.totalPrice.indexOf(params.totalPrice)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.totalFee||params.totalFee==''){if(orderProductFee.totalFee.indexOf(params.totalFee)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.orderCount||params.orderCount==''){if(orderProductFee.orderCount.indexOf(params.orderCount)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.id||params.id==''){if(orderProductFee.id.indexOf(params.id)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.bizDate||params.bizDate==''){if(orderProductFee.bizDate.indexOf(params.bizDate)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.startComputedDate||params.startComputedDate==''){if(orderProductFee.startComputedDate.indexOf(params.startComputedDate)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.computedStatus||params.computedStatus==''){if(orderProductFee.computedStatus.indexOf(params.computedStatus)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.goodsName||params.goodsName==''){if(orderProductFee.goodsName.indexOf(params.goodsName)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.shopCount||params.shopCount==''){if(orderProductFee.shopCount.indexOf(params.shopCount)>=0){isTrue=true;}else{isTrue=false;}}
      	return isTrue;
	  });
      if(!config.params.currentPage){ 
	      return new Promise((resolve, reject) => {
	        setTimeout(() => {
	          resolve([200, {
	            data: mockOrderProductFees
	          }]);
	        }, 1000);
	      });
      }
    
      let {pageSize,currentPage, total} = config.params;
      total = mockOrderProductFees.length;
      mockOrderProductFees = mockOrderProductFees.filter((orderProductFee, index) => index < pageSize * currentPage && index >= pageSize * (currentPage - 1));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            pageInfo: {
            	total:total
            },
            data: mockOrderProductFees,
            tips:{
            	isOk:true,
            	msg:'查询成功'
            }
          }]);
        }, 1000);
      });
    });

    //删除
    mock.onPost('/mk/mng/computed/day/orderProductFee/del').reply(config => {
      var params = JSON.parse( config.data );
      let {  id  } = params;
      _OrderProductFees = _OrderProductFees.filter(orderProductFee => orderProductFee.id !== id);
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //批量删除
    mock.onPost('/mk/mng/computed/day/orderProductFee/batchDel').reply(config => {
      var params = JSON.parse( config.data );
      _OrderProductFees = _OrderProductFees.filter(orderProductFee => !params.includes(orderProductFee.id));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
           tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //编辑
    mock.onPost('/mk/mng/computed/day/orderProductFee/edit').reply(config => {
      var params = JSON.parse( config.data );
      let { goodsId,nums,totalPrice,totalFee,orderCount,id,bizDate,startComputedDate,computedStatus,goodsName,shopCount } = params;
      _OrderProductFees.some(orderProductFee => {
        if (orderProductFee.id === id) {
			orderProductFee.goodsId = goodsId;
			orderProductFee.nums = nums;
			orderProductFee.totalPrice = totalPrice;
			orderProductFee.totalFee = totalFee;
			orderProductFee.orderCount = orderCount;
			orderProductFee.id = id;
			orderProductFee.bizDate = bizDate;
			orderProductFee.startComputedDate = startComputedDate;
			orderProductFee.computedStatus = computedStatus;
			orderProductFee.goodsName = goodsName;
			orderProductFee.shopCount = shopCount
          return true;
        }
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'编辑成功'
            }
          }]);
        }, 500);
      });
    });

    //新增
    mock.onPost('/mk/mng/computed/day/orderProductFee/add').reply(config => {
      var params = JSON.parse( config.data );
      let { goodsId,nums,totalPrice,totalFee,orderCount,id,bizDate,startComputedDate,computedStatus,goodsName,shopCount } = params;
      _OrderProductFees.push({
		goodsId:goodsId,
		nums:nums,
		totalPrice:totalPrice,
		totalFee:totalFee,
		orderCount:orderCount,
		id:id,
		bizDate:bizDate,
		startComputedDate:startComputedDate,
		computedStatus:computedStatus,
		goodsName:goodsName,
		shopCount:shopCount
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'新增成功'
            }
          }]);
        }, 500);
      });
    });

  }
};